import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.dealerId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dealerId',
                defaultMessage: '总代'
            })
        );
    if(!data || !data.dutyUnitId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dutyUnitId',
                defaultMessage: '供应商'
            })
        );
    if(!data || !data.productCategoryId)
        requiredFields.push(
            formatMessage({
                id: 'validator.productCategoryId',
                defaultMessage: '产品分类'
            })
        );
    if(!data || !data.deduction)
        requiredFields.push(
            formatMessage({
                id: 'validator.deduction',
                defaultMessage: '扣款单号'
            })
        );
    if(!data || !data.partId)
        requiredFields.push(
            formatMessage({
                id: 'validator.partId',
                defaultMessage: '备件'
            })
        );
    if(!data || !data.qty)
        requiredFields.push(
            formatMessage({
                id: 'validator.qty',
                defaultMessage: '数量'
            })
        );
    if(!data || !data.laborFee)
        requiredFields.push(
            formatMessage({
                id: 'validator.laborFee',
                defaultMessage: '工时费'
            })
        );
    if(!data || !data.totalAmount)
        requiredFields.push(
            formatMessage({
                id: 'validator.totalAmount',
                defaultMessage: '费用合计'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
